<script lang="ts" setup>
import { ref } from 'vue';
import { FormRule } from 'tdesign-vue-next';

const INIT_DATA: any = { enable: false, server_adr: '', port_num: '' };
const list = ref([
  { label: '服务器启用禁用', value: false, key: 'enable', type: 'SwitchView' },
  {
    label: '服务器地址',
    value: '',
    key: 'server_adr',
    type: 'InputView',
    placeholder: '请输入服务器地址',
    clearable: true,
  },
  {
    label: '端口号',
    value: '',
    key: 'port_num',
    type: 'InputView',
    placeholder: '请输入端口号',
    clearable: true,
  },
]);
const FORM_RULES: Record<string, FormRule[]> = {
  enable: [{ required: true, message: '请选择', trigger: 'blur' }],
  server_adr: [{ required: true, message: '请输入服务器地址', trigger: 'blur' }],
  port_num: [{ required: true, message: '请输入端口号', trigger: 'blur' }],
};
const formData = ref({ ...INIT_DATA });

const saveFun = () => {};
</script>

<template>
  <div class="server-wrap">
    <div class="content-wrap">
      <div class="common-scrollbar form-wrap full">
        <t-form ref="formRef" :rules="FORM_RULES" :data="formData" :colon="true" :label-width="100" label-align="left">
          <div class="common-item-view">
            <t-row :gutter="[0, 30]">
              <t-col v-for="(item, index) in list" :key="index" :span="12">
                <div class="item">
                  <form-item :form-data="formData" :data="item">
                    <template #self_name>
                      <t-input></t-input>
                    </template>
                  </form-item>
                </div>
              </t-col>
            </t-row>
          </div>
        </t-form>
      </div>
    </div>
    <div class="save-btn">
      <t-button class="common-button" style="width: 80px" theme="primary" @click="saveFun"> 保存 </t-button>
    </div>
  </div>
</template>

<style lang="less" scoped>
.server-wrap {
  width: 100%;

  .content-wrap {
    background-color: #fff;
    padding: 20px 5px 34px;
    margin-top: 10px;
  }
  .common-item-view {
    margin-bottom: 0;
  }
  .save-btn {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 40px;
  }
  :deep(.t-form__label) {
    width: 120px !important;
    margin-right: 13px;
    padding-right: 0;
    text-align: end;
  }
}
</style>
